package edu.xaut.bookingsys.service;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.hutool.log.level.Level;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.xaut.bookingsys.entity.CourseSession;
import edu.xaut.bookingsys.entity.EnumLevel;
import edu.xaut.bookingsys.entity.InfoTeacher;
import edu.xaut.bookingsys.mapper.CourseSessionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseSessionService extends ServiceImpl<CourseSessionMapper, CourseSession> {
    @Autowired
    private CourseSessionMapper mapper;

    Log log= LogFactory.get();

    public CourseSession getCurSession () throws RuntimeException
    {
        var wrapper = new LambdaQueryWrapper<CourseSession>();
        List<CourseSession> courseSessions = mapper.selectList(wrapper.eq(CourseSession::isCurSession, true));
        if(courseSessions.size()!=1) {
            log.error(new RuntimeException("数据库中存储的当前学期值不正确"),"数据库中存在{}条当前学期，应该只有1个",courseSessions.size());
        }
        return courseSessions.get(0);
    }
}
